define(["webgl", "assetSyst", "baseAsset"], function(webgl, assetSyst, baseAsset) {	
	return {
	
		create : function(path) {
			var splits 	= (path.split('.')[0]).split('|');
			
			var _vs; //		= assetSyst.get(splits[0] + "." + splits[2]);
			var _fs; //		= assetSyst.get(splits[1] + "." + splits[2]);
			var _uniforms 	= [];
			var _attributes	= [];
			
			//Create WebGL Shader Program
			function createProgram() {
				//link
				var gl= webgl.gl;
				var p = gl.createProgram();
				gl.attachShader(p, _vs.shader);
				gl.attachShader(p, _fs.shader);
				gl.linkProgram(p);
				if(!gl.getProgramParameter(p, gl.LINK_STATUS)) {
					alert("assetShaderProgram.js : LINK SHADER FAILED!");
				}
				
				asset.program = p;
			}
			
			//Get attribute location
			function getAttrLoc(name) {
				var a = webgl.gl.getAttribLocation(asset.program, name);
				webgl.gl.enableVertexAttribArray(a);
				return a;
			}
			
			function onShaderLoaded(shader, params) {
				if(_vs.isLoaded() && _fs.isLoaded()) {
					createProgram();
					asset.loadState	= baseAsset.loadState.LOADED;
					callback 		= params[0];
					params			= params[1];
					callback(asset, params);
				}
			}
			
			var asset = baseAsset.create(path);
			
			asset.program = null;
			
			asset.load = function(callback, params) {
				this.loadState = baseAsset.loadState.LOADING;
				_vs = assetSyst.get(splits[0] + "." + splits[2], onShaderLoaded, [callback, params]);
				_fs = assetSyst.get(splits[1] + "." + splits[2], onShaderLoaded, [callback, params]);
			};
			
			asset.unload = function() {
				if(!this.program) return;
				this.loadState = baseAsset.loadState.NOT_LOADED;
				webgl.gl.deleteProgram(this.program);
				this.program = null;
			};
			
			asset.getUniform = function(name) {
				return 	!_uniforms[name] ? 
						_uniforms[name] = webgl.gl.getUniformLocation(asset.program, name) :
						_uniforms[name];
			};
			
			asset.getAttribute = function(name) {
				return  !_attributes[name] ? 
						(_attributes[name] = getAttrLoc(name)) :
						_attributes[name];
			}
			
			return asset;
		} 
	};
});